package se.slackers.sounder.algorithm;

public abstract class AbstractRule implements Rule {
	public static final int LIVE = 1;
	public static final int DEAD = 0;

	private int width;
	private int height;

	public void compute(final float[] source, final float[] dest, final int w, final int h) {
		width = w;
		height = h;
		step(source, dest, w, h);
	}

	public void param(final int n, final float value) {
	}

	abstract void step(final float[] source, final float[] dest, final int w, final int h);

	protected synchronized float get(final float[] buffer, final int x, final int y) {
		// if (x < 0) {
		// x += width;
		// }
		// x = x % width;
		//
		// if (y < 0) {
		// y += height;
		// }
		// y = y % height;

		if (x < 0 || x >= width || y < 0 || y >= height) {
			return 0;
		}
		return buffer[x + y * width];
	}
}
